package goodbaby.dklt.activity;

import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.classic.core.activity.BaseActivity;
import com.classic.core.utils.ToastUtil;
import com.classic.okhttp.gbb.http.ActionHelp;
import com.classic.okhttp.gbb.http.ObjectCallback;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.List;

import goodbaby.dklt.R;
import goodbaby.dklt.adapter.LeaveHistoryAdapter;
import goodbaby.dklt.bean.LeaveBean;

/**
 * Created by Jayden on 2016/5/4 11:26.
 *
 * @version V1.0
 * @Title: LeaveHistoryActivity
 * @Description: 请假历史
 */
public class LeaveHistoryActivity extends BaseActivity {

    private LeaveHistoryAdapter adapter;
    private ImageView ivBack;
    private ListView lvLeave;
    private TextView tvTitle;

    private void getLeaveHistoryData() {
        ActionHelp.gbbLeaveDetail(this, new ObjectCallback<List<LeaveBean>>() {

            public void onError(int paramAnonymousInt) {
                ToastUtil.showToast(LeaveHistoryActivity.this, "失败");
            }

            public void onError(int paramAnonymousInt, String paramAnonymousString) {
                super.onError(paramAnonymousInt, paramAnonymousString);
                ToastUtil.showToast(LeaveHistoryActivity.this, "失败");
            }

            public void onSuccess(List<LeaveBean> paramAnonymousList) {
                adapter = new LeaveHistoryAdapter(LeaveHistoryActivity.this, paramAnonymousList);
                lvLeave.setAdapter(adapter);
            }

            @Override
            public Type getType() {
                return new TypeToken<List<LeaveBean>>() {
                }.getType();
            }
        });
    }

    public int getLayoutResId() {
        return R.layout.activity_leave_history;
    }

    public void initData() {
        super.initData();
    }

    public void initView() {
        super.initView();
        tvTitle = (TextView) findViewById(R.id.tv_common_title);
        tvTitle.setText("请假记录");
        ivBack = (ImageView) findViewById(R.id.iv_common_back);
        ivBack.setVisibility(View.VISIBLE);
        ivBack.setOnClickListener(this);
        lvLeave = (ListView) findViewById(R.id.lv_leave_history);
        getLeaveHistoryData();
    }

    public void viewClick(View paramView) {
        super.viewClick(paramView);
        switch (paramView.getId()) {
            default:
                break;
            case R.id.iv_common_back:
                finish();
                break;
        }
    }
}
